package se392.ateam2006.resourcemgmt.equipment;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;

import se392.ateam2006.resourcemgmt.room.RoomEntity;

/**
 * Entity class to define the attributes and operations of a piece of equipment (owner, room, etc)
 * This information can then be persisted into a database
 * @author Ateam (Matthew Bennett, Claire Melton, Shingai Manyiwa, John Adderley)
 * @version 25/03/07
 */
@Entity
public class EquipmentEntity implements Serializable {
    
    @Id
    private String id;
    private String roomType; 
    private RoomEntity theRoom;
    private boolean fixed;
    private String owner;
    
    /**
     * Default constructor required as this is an entity class
     */
    public EquipmentEntity() { }
    
    /**
     * Creates a new instance of EquipmentEntity
     * @param id - the id of the piece of equipment
     * @param room - a RoomEntity that defines the room that the equipment belongs to
     * @param fixed - boolean. Can the equipment be moved from room to room?
     * @param owner - string containing the owner of the piece of equipment
     */
    public EquipmentEntity(String id, String type, RoomEntity room, boolean fixed, String owner) {
        
        this.id = id;
        this.roomType = type;
        this.theRoom = room;
        this.fixed = fixed;
        this.owner = owner;
    }    

    /**
     * Override the equals method...
     * @return boolean - are the two objects the same?
     */
    public boolean equals(Object obj) {
        if(obj instanceof EquipmentEntity) {
            
            EquipmentEntity otherItem = (EquipmentEntity)(obj);
            
            if(this.getId().equals(otherItem.getId())){
                return true;
            }else{
                return false;
            }
        }
        
        return false;
    }

    /**
     * Get the ID of the piece of equipment
     * @return String - equipment ID
     */
    public String getId() {
        return id;
    }

    /**
     * Set the ID of the piece of equipment
     * @param id - the new ID
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * Get the type of the piece of equipment
     * @return String - equipment type
     */
    public String getType() {
        return roomType;
    }

    /**
     * Set the type of the piece of equipment
     * @param type - the new type
     */
    public void setType(String type) {
        this.roomType = type;
    }

    /**
     * Get the room that the piece of equipment belongs to
     * @return RoomEntity - the owning room
     */
    public RoomEntity getRoom() {
        return theRoom;
    }

    /**
     * Set the room that owns the piece of equipment
     * @param room - the new owning room
     */
    public void setRoom(RoomEntity room) {
        this.theRoom = room;
    }

    /**
     * Get the fixed flag of the piece of equipment
     * @return boolean - is the piece of equipment fixed?
     */
    public boolean isFixed() {
        return fixed;
    }

    /**
     * Set the fixed flag of the piece of equipment
     * @param fixed - the new state of the flag
     */
    public void setFixed(boolean fixed) {
        this.fixed = fixed;
    }

    /**
     * Get the owner of the piece of equipment
     * @return String - equipment owner
     */
    public String getOwner() {
        return owner;
    }

    /**
     * Set the owner of the piece of equipment
     * @param owner - the new owner
     */
    public void setOwner(String owner) {
        this.owner = owner;
    }
}
